# import jwt
#
# import time
# class MyJwt:
#     def __init__(self):
#         self.SECRET_KEY='asfsf!#$#$@$#^%#$sdfwtwa134342432323fffwf'
#     #生成jwt
#     def jwt_encode(self,data):
#         token = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
#         print(token)
#         return token
#     #解密jwt
#     def jwt_decode(self,token):
#         try:
#             data = jwt.decode(token,self.SECRET_KEY,algorithm='HS256')
#             #重新加密获取新的token
#             newtoken = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
#             return str(newtoken,encoding='utf8')
#         except:
#             return None
#
#     #对比
#     def check(self,token,newtoken):
#         # if token == newtoken:
#         #     return True
#         # return False
#
#         try:
#             data = jwt.decode(token,self.SECRET_KEY,algorithm='HS256')
#             #重新加密获取新的token
#             newtoken = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
#             return str(newtoken,encoding='utf8')
#         except:
#             if token == newtoken:
#                 return True
#         return False
#
# myjwt = MyJwt()
#
# # token = myjwt.jwt_encode({'data':{'name':'sdf'}})
# #
# # print(token)
# import base64

import jwt
import datetime

class mytoken():
    def encode_jwt(self,id,time,myword):
        info={
            "exp":int((datetime.datetime.now()+datetime.timedelta(seconds=time)).timestamp()),
            "uid":id
        }
        jwt_token = jwt.encode(info,myword,algorithm="HS256")
        return jwt_token

    def decode_jwt(self,token,myword):
        res = jwt.decode(token,myword,algorithms="HS256")
        return res

token1 = mytoken()
# print(token1.encode_jwt(1,60,"123"))
# print(token1.decode_jwt("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2Mzk3NDM0OTksInVpZCI6MX0.C0rWFHjDYPDm-JgodVFfHkkNn1tcuvv7U2SuZvu3zEM","123"))
